package com.zeedev.flyingsaucer.data;

import android.content.ContentValues;
import mobi.zeedev.flyingsaucer.common.DataModule.tree.DatabaseNode;
import mobi.zeedev.flyingsaucer.common.DataModule.tree.DatabaseTree;
import mobi.zeedev.flyingsaucer.common.DataModule.tree.DatabaseType;
import mobi.zeedev.flyingsaucer.common.DataModule.tree.Node;

import java.util.LinkedList;
import java.util.List;

/**
 * User: James
 * Date: 1/29/11
 * Time: 10:38 AM
 */
public class ContentValuesDatabaseTree {


    public static List<ContentValues> getContentValues(DatabaseTree tree) {
        List<ContentValues> list = new LinkedList<ContentValues>();

        for (DatabaseNode node : tree) {
            if (node.getType() == DatabaseType.PRIMARY_KEY) {
                ContentValues cv = new ContentValues();
                cv.put(node.getColumnName().toString(), node.getValue().toString());
                for (Node<Void> unCastedNode : node.getChildren()) {
                    DatabaseNode innerNode = (DatabaseNode) unCastedNode;
                    cv.put(innerNode.getColumnName().toString(), innerNode.getValue().toString());
                }
                list.add(cv);
            }
        }


        return list;
    }




}
